#include "AttributeEditor.h"
#include "../core/src/container/Attribute.h"

namespace Xps
{
	AttributeEditor::AttributeEditor(QWidget *parent) : Editor(parent)
	{
		setObjectName("AttributeEditor");
		QGridLayout* content_layout = new QGridLayout();

		setLayout(content_layout);

		name = new QLineEdit();
		weight = new QLineEdit();
		desc = new QTextEdit();
				
		content_layout->addWidget(new QLabel("Name:"),0, 0);
		content_layout->addWidget(name, 0, 1);
		content_layout->addWidget(new QLabel("Weight:"),1, 0);
		content_layout->addWidget(weight, 1, 1);
		content_layout->addWidget(new QLabel("Description:"),2,0,1,2);
		content_layout->addWidget(desc, 3,0,1,2);
	}

	void AttributeEditor::write(XpsAssets::AssetData* ad)
	{
		XpsAssets::Attribute* a = (XpsAssets::Attribute*) ad;

		a->setName(name->text());
		a->setDesc(desc->toPlainText());
		a->setWeight(weight->text().toInt());
	}

	void AttributeEditor::read(XpsAssets::AssetData* ad)
	{
		XpsAssets::Attribute* a = (XpsAssets::Attribute*) ad;

		name->setText(a->name());
		desc->setText(a->desc());
		weight->setText(QString("%1").arg(a->weight()));
	}
}